package com.zs4sdk.activity;

import java.util.HashMap;
import java.util.Map;

import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.zs4sdk.common.Extra;
import com.common.library.util.Helper;
import com.common.library.util.ParamsHelper;

public abstract class Zs4GameBaseWebActivity extends Zs4GameBaseActivity {

	private static final String TAG = Zs4GameBaseWebActivity.class.getSimpleName();


	protected WebView mWebView;
	private Map<String, String> mHeaderMap;

	
	/**
	 * 
	 * function: 取得请求头部
	 *
	 * @return
	 * 
	 * @ author: aXiBa 2013-3-15 下午2:42:54
	 */
	protected Map<String, String> getHeader(){
		if (this.mHeaderMap == null){
			mHeaderMap = new HashMap<String, String>();
		}
		if (!mHeaderMap.containsKey(Extra.NETWORK_KEY_USER_AGENT1)){
			mHeaderMap.put(Extra.NETWORK_KEY_USER_AGENT1, ParamsHelper.getUserAgent1());
		}
		return this.mHeaderMap;
	}
	
	
	
	@Override
	protected void init() {
		super.init();
		//初始化WebView
		this.mWebView = findView(WebView.class, "zs4gameviewid_web_container");
		if (Helper.isNotNull(this.mWebView)){
			this.mWebView.requestFocus();
			this.mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
			this.mWebView.getSettings().setSupportZoom(false);
			this.mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
			this.mWebView.getSettings().setBuiltInZoomControls(false);
			this.mWebView.setWebViewClient(this.createWebViewClient());
			this.mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
		}
	}
	@Override
	public void onClick(View v) {
		super.onClick(v);
	}

	
	/**
	 * 创建WebViewClient
	 * @return
	 */
	protected abstract WebViewClient createWebViewClient();
	
	
	/**
	 * 刷新页面
	 */
	protected void refreshWebView(){
		this.mWebView.reload();
	}
	

	public void setWebView(WebView webView){
		this.mWebView = webView;
	}

	public WebView getWebView(){
		return this.mWebView;
	}
	
}
